﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Showroom.BLL;

namespace MobileWeb
{
    public partial class ProductDetail : System.Web.UI.Page
    {
        private int ProductID
        {
            get
            {
                return string.IsNullOrEmpty(Request["id"]) ? 0 : Convert.ToInt32(Request["id"]);
            }
        }

        private int CategoryID
        {
            get
            {
                return string.IsNullOrEmpty(Request["cid"]) ? 0 : Convert.ToInt32(Request["cid"]);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                View_Products prod = View_Products.GetByProductID(ProductID);
                ((Site)Page.Master).SetTitlePage(prod.s_Name);
                //Load image
                ProductImages pImgs = ProductImages.GetByProductID(prod.ID);
                rptListImage.DataSource = pImgs.DefaultView;
                rptListImage.DataBind();

                lblDescription.Text = prod.s_Description;
                lblPrice.Text = (string.IsNullOrEmpty(prod.s_Price) || prod.Price == 0) ? "" : string.Format("<span class=\"price\">{0}</span>", String.Format("{0:C}", prod.Price));

                View_Category cat = new View_Category();
                cat.Where.ID.Value = CategoryID;
                cat.Query.Load();

                ((Site)Page.Master).SetBackUrl(string.Format("Products.aspx?cat={0}_{1}", cat.Name, cat.ID));
            }
        }
    }
}